//    Copyright (C) Kherty.  All rights reserved.
using System.Windows.Media;
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing
{
    internal class Path2DCubicBezierTo : PathElement
    {
        private AdjPoint2D point1;

        private AdjPoint2D point2;

        private AdjPoint2D point3;

        public AdjPoint2D Point1
        {
            get { return point1; }
            set { point1 = value; }
        }

        public AdjPoint2D Point2
        {
            get { return point2; }
            set { point2 = value; }
        }

        public AdjPoint2D Point3
        {
            get { return point3; }
            set { point3 = value; }
        }

        public override PathSegment Segment
        {
            get
            {
                return new BezierSegment(
                    Point1.ToPoint(),
                    Point2.ToPoint(),
                    Point3.ToPoint(), true);
            }
        }


        internal override void ReadXmlCore(ReadContext context)
        {
            using (var c = context.Read("cubicBezTo"))
            {
                Point1 = c.ReadElementAs<AdjPoint2D>("pt");
                Point2 = c.ReadElementAs<AdjPoint2D>("pt");
                Point3 = c.ReadElementAs<AdjPoint2D>("pt");
            }
        }

        internal override void WriteXmlCore(WriteContext context)
        {
            using (WriteContext c = context.Write("cubicBezTo"))
            {
                c.WriteElementAs(Point1, "pt");
                c.WriteElementAs(Point2, "pt");
                c.WriteElementAs(Point3, "pt");
            }
        }
    }
}